package logic

import (
	"context"
	"wei/weirpc/weirpcclient"

	"wei/api/internal/svc"
	"wei/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type SendSmsLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewSendSmsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SendSmsLogic {
	return &SendSmsLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *SendSmsLogic) SendSms(req *types.SendSmsRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	sms, err := l.svcCtx.WeiRpc.SendSms(l.ctx, &weirpcclient.SendSmsRequest{
		Account: req.Account,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Data:    500,
			Code:    nil,
		}, nil
	}
	return &types.Response{
		Message: "短信验证码获取成功",
		Data:    200,
		Code:    sms,
	}, nil

}
